<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" >
      <el-form-item label="bom名称" prop="code">
        <el-input
          v-model="queryParams.code"
          placeholder="请输入bom名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="Product" prop="productTmplId">
        <el-input
          v-model="queryParams.productTmplId"
          placeholder="请输入Product"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="Product Variant" prop="productId">
        <el-input
          v-model="queryParams.productId"
          placeholder="请输入Product Variant"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="库内产品数量" prop="productQty">
        <el-input
          v-model="queryParams.productQty"
          placeholder="请输入库内产品数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="单位" prop="productUomId">
        <el-input
          v-model="queryParams.productUomId"
          placeholder="请输入单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="Sequence" prop="sequence">
        <el-input
          v-model="queryParams.sequence"
          placeholder="请输入Sequence"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="路线" prop="routingId">
        <el-input
          v-model="queryParams.routingId"
          placeholder="请输入路线"
          clearable
          @keyup.enter.native="handleQuery"
        /> 
      </el-form-item>-->
      <!-- <el-form-item label="准备生产" prop="readyToProduce">
        <el-input
          v-model="queryParams.readyToProduce"
          placeholder="请输入准备生产"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="Operation Type" prop="pickingTypeId">
        <el-input
          v-model="queryParams.pickingTypeId"
          placeholder="请输入Operation Type"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="Company" prop="companyId">
        <el-input
          v-model="queryParams.companyId"
          placeholder="请输入Company"
          clearable
          @keyup.enter.native="handleQuery"
        /> 
      </el-form-item>-->
      <!-- <el-form-item label="Last Message Date" prop="messageLastPost">
        <el-date-picker clearable
          v-model="queryParams.messageLastPost"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择Last Message Date">
        </el-date-picker>
      </el-form-item> -->
      <!-- <el-form-item label="创建者" prop="createUid">
        <el-input
          v-model="queryParams.createUid"
          placeholder="请输入创建者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="创建日期" prop="createDate">
        <el-date-picker clearable
          v-model="queryParams.createDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建日期">
        </el-date-picker>
      </el-form-item>
      <!-- <el-form-item label="最后更新者" prop="writeUid">
        <el-input
          v-model="queryParams.writeUid"
          placeholder="请输入最后更新者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="最后更新日期" prop="writeDate">
        <el-date-picker clearable
          v-model="queryParams.writeDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择Last Updated on">
        </el-date-picker>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">    
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="AddBom"       
        >新增物料清单</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:bom:add']"
        >新增</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:bom:edit']"
        >修改</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:bom:remove']"
        >删除</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"         
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="bomList" @selection-change="handleSelectionChange" @row-click="detail">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="bom名称" align="center" prop="code" />
      <!-- <el-table-column label="启用状态" align="center" prop="active" /> -->
      <!-- <el-table-column label="类型" align="center" prop="type" /> -->
      <!-- <el-table-column label="Product" align="center" prop="productTmplId" /> -->
      <!-- <el-table-column label="Product Variant" align="center" prop="productId" /> -->
      <el-table-column label="库内产品数量" align="center" prop="productQty" />
      <el-table-column label="单位" align="center" prop="productUomId" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.stock_uom" :value="scope.row.productUomId" />
        </template>
        </el-table-column>
      <!-- <el-table-column label="Sequence" align="center" prop="sequence" /> -->
      <!-- <el-table-column label="路线" align="center" prop="routingId" /> -->
      <!-- <el-table-column label="准备生产" align="center" prop="readyToProduce" /> -->
      <!-- <el-table-column label="Operation Type" align="center" prop="pickingTypeId" /> -->
      <!-- <el-table-column label="Company" align="center" prop="companyId" /> -->
      <!-- <el-table-column label="Last Message Date" align="center" prop="messageLastPost" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.messageLastPost, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="创建者" align="center" prop="createUid" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.boshien_emp" :value="scope.row.createUid" />
        </template>
        </el-table-column>
      <el-table-column label="创建日期" align="center" prop="createDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="最后更新者" align="center" prop="writeUid" /> -->
      <!-- <el-table-column label="最后更新日期" align="center" prop="writeDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.writeDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-document"
            @click="detail(scope.row)"        
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click.stop="Toeditbom(scope.row)"         
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click.stop="handleDelete(scope.row)"
            v-hasPermi="['system:bom:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>   
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    
  </div>
</template>

<script>
import { listBom, getBom, delBom, addBom, updateBom } from "@/api/system/bom";
import bomdetail from '@/views/system/bomdetail/index'
import bomadd from '@/views/system/bomadd/index'
import bomedit from '@/views/system/bomedit/index'
export default {
  name: "Bom",
  dicts: ['boshien_emp','stock_uom'],

  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 物料清单表格数据
      bomList: [],
      // 弹出层标题
      title: "",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        code: null,
        active: null,
        type: null,
        productTmplId: null,
        productId: null,
        productQty: null,
        productUomId: null,
        sequence: null,
        routingId: null,
        readyToProduce: null,
        pickingTypeId: null,
        companyId: null,
        messageLastPost: null,
        createUid: null,
        createDate: null,
        writeUid: null,
        writeDate: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [
          { required: true, message: "id不能为空", trigger: "blur" }
        ],
        type: [
          { required: true, message: "类型不能为空", trigger: "change" }
        ],
        productTmplId: [
          { required: true, message: "Product不能为空", trigger: "blur" }
        ],
        productQty: [
          { required: true, message: "库内产品数量不能为空", trigger: "blur" }
        ],
        productUomId: [
          { required: true, message: "Product Unit of Measure不能为空", trigger: "blur" }
        ],
        readyToProduce: [
          { required: true, message: "Manufacturing Readiness不能为空", trigger: "blur" }
        ],
        companyId: [
          { required: true, message: "Company不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
     // 新增物料清单
     AddBom() { 
      this.$router.push({
        path: "/bomadd",
        component: bomadd,
        redirect: "noRedirect",
        hidden: false,
        alwaysShow: true,
        // query: { listId: 574 },
        query: { },

      });
      
    },
    // 修改物料清单
    Toeditbom(row) {
      const id=row.id
      this.$router.push({
        path: "/bomedit",
        component: bomedit,
        redirect: "noRedirect",
        hidden: false,
        alwaysShow: true,
        query: { listId:id },
      });
    },
    /** 查询物料清单列表 */
    getList() {
      this.loading = true;
      listBom(this.queryParams).then(response => {
        this.bomList = response.rows;
        // console.log(response);
        this.total = response.total;
        this.loading = false;
      });
    },
     // 查询详情按钮
     detail(row) {
      const id = row.id
      this.$router.push({
        path: "/bomdetail",
        component: bomdetail,
        redirect: "noRedirect",
        hidden: false,
        alwaysShow: true,
        // query: { listId: 1290 },
        query: { listId:id },
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },   
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除物料清单编号为"' + ids + '"的数据项？').then(function() {
        return delBom(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/bom/export', {
        ...this.queryParams
      }, `bom_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
